package org.thanos.demo.controller;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@RestController
@RequestMapping(path = "/api/v1.0")
public class LoginController {

    @GetMapping(path = "/ping")
    public LocalDateTime ping() {
        return LocalDateTime.now();
    }

    @PostMapping(path = "/login")
    public void login(@RequestBody LoginVo loginVo) {
        Subject subject = SecurityUtils.getSubject();
        UsernamePasswordToken token = new UsernamePasswordToken(loginVo.getLoginId(), loginVo.getPassword());
        subject.login(token);
    }

    @GetMapping(path = "/logout")
    public void logout() {
        Subject subject = SecurityUtils.getSubject();
        subject.logout();
    }
}
